

#ifndef _h_queue
#define _h_queue

struct queue {
  volatile short        head;
  volatile short         tail;
  short                queue_size;
  short                buf_size;
  char              *buf;
};
typedef struct queue queue_t;


void        init_queue (queue_t *Q, int qsz, int bsz, char *buf);
char *      enqueue_buffer (queue_t *Q);
char *      enqueue_buffer_blocking (queue_t *Q);
void        enqueue (queue_t *Q);
char *      dequeue_buffer (queue_t *Q);
char *      dequeue_buffer_blocking (queue_t *Q);
void        dequeue (queue_t *Q);

/**

  Example use:

#include "queue.h"


#define QUEUE_SIZE    2
#define BUF_SIZE    100

char buf[ QUEUE_SIZE * BUF_SIZE ];

queue_t        Q;

main () {
  init_queue (&Q, QUEUE_SIZE, BUF_SIZE, buf);
  ...
  pthread_create (... producer ...);
  pthread_create (... consumer ...);
  ...

}

void *
producer (....)
{
   char *p;

   p = enqueue_buffer (&Q, 2, 100, buf);
   ... fill in some data into p[ ] ...
   ... once done, commit the queue ...
   enqueue (&Q);

}

void *
consumer (....)
{
   char *p;

   p = dequeue_buffer (&Q);
   ... use the data ...
   ... once done, commit the queue ...
   dequeue (&Q);

}


  **/

extern queue_t         Phy2MacQueue;


#endif
